#include <string.h>
#include "common.h"

int main(int argc, char* argv[])
{
    X509 *cert;
    // 从文件中加载证书
    FILE *cert_file = fopen("/home/ts/document/zhb/ca/user.pem", "r");
    cert = PEM_read_X509(cert_file, NULL, NULL, NULL);
    fclose(cert_file);

    AUTHORITY_KEYID *authorityKeyId = X509_get_ext_d2i(cert, NID_authority_key_identifier, NULL, NULL);
    if (authorityKeyId == NULL) {
        printf("Failed to get authorityKeyId in openssl!");
        return CF_ERR_CRYPTO_OPERATION;
    }

	CfBlob out;
	out.size = authorityKeyId->keyid->length;
	out.data = (unsigned char*)malloc(out.size);
	memcpy(out.data, (const char *)authorityKeyId->keyid->data, out.size);

	printf("out.size=%d.\n", out.size);
	for(int index=0; index <out.size; index++)
	{
		if(index%8 == 0)
		{
			printf("\n");
		}
		printf("0x%02x, ", out.data[index]);
	}
	printf("\n");

	return DEFAULT_SUCCESS;
}

